package net.openvision.music.composition;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import net.openvision.music.model.Length;

/**
 * This class provides a most abstract view of a musical score. It represents it
 * as a so called multi sequence, which is a sequence of integer arrays. A
 * single integer array is called an element of the multi sequence and
 * corresponds to a chord in musical terminology. Every element has an according
 * weight, which allows indication of musical meter and a length.
 * 
 * @author Hannes Widmoser
 * 
 */
public class MultiSequence implements Iterable<Element> {
	private List<Element> elements;
	private int elementSize;
	
	
	public MultiSequence(int elementSize) {
		elements = new ArrayList<Element>();
		this.elementSize = elementSize;
	}
	
	public void add(ElementValue value, Length length, double weight) {
		elements.add(new Element(value, weight, length, this, elements.size()));
	}

	/**
	 * Gets the element with the associated index.
	 * 
	 * @param index
	 *            the position of the element in the sequence
	 * @return the element that is at the given position in the sequence
	 */
	public Element getElement(int index) {
		return elements.get(index);
	}

	/**
	 * Gets the length of the element arrays. Every element in the multi
	 * sequence has to be of the same length
	 * 
	 * @return the length of the element arrays
	 */
	public int getElementSize() {
		return elementSize;
	}

	@Override
	public Iterator<Element> iterator() {
		return elements.iterator();
	}

}
